import { Component, OnInit, ViewChild } from '@angular/core';
import { User } from '../user';
import { UserService } from '../user.service';

@Component({
  selector: 'app-table',
  templateUrl: './table.component.html',
  styleUrls: ['./table.component.css']
})
export class TableComponent implements OnInit {
  @ViewChild('model') model: any

  //被修改的用户的id
  ngOnInit(): void {
  }

  constructor(private userService: UserService) {
  }

  getUsers(): User[] {
    return this.userService.getUsers();
  }

  deleteRow(id: string): void {
    // this.listOfData = this.listOfData.filter(d => d.id !== id);
    this.userService.deleteUser(id);
  }

  //编辑用户信息
  editUser(id: string, e: MouseEvent): void {
    this.model.setEditingUser(id);
    // this.model.setButtonName("确认修改");
    this.model.upateNzTitle();
    this.model.showModal(e, "确认修改");
  }

}
